Fix tenant ID validation error handling in sam local start-api#8453
Conversation
… without tenant-id header when using sam local start-api
|
let's add a test to make sure this error is throw as expected |
roger-zhangg
left a comment
There was a problem hiding this comment.
Is this test actually doing anything? Is it like you are throwing an TenantIdValidationError in the test and assert the same error is thrown? Ideally we should just invoke the function with the condition (tenancy function without tenant ID, or non-tenant function with tenant ID) and assert the error. You should not use invoke_mock.side_effect directly. Or it's like the test is testing itself
This test is specifically testing error handling, not validation logic. The actual tenant-id validation logic is already tested in For the API Gateway service test, the responsibility is different - it needs to verify that when TenantIdValidationError is raised (from the lambda runner), the API Gateway service correctly:
|
roger-zhangg
left a comment
There was a problem hiding this comment.
let's add test back after release
| response_data = jsonify({"message": str(e)}) | ||
| endpoint_service_error = make_response(response_data, 400) # HTTP 400 Bad Request |
There was a problem hiding this comment.
It would be better to be consistent with the other Errors and add a new method inside the ServiceErrorResponses class instead of calling make_response right here.
But it's just a code refactor that's not critical.
Add proper exception handling for TenantIdValidationError in API Gateway
service to return HTTP 400 Bad Request with the actual validation message
instead of generic "Internal server error".
Before this change, if user do sam local start-api and invoke a multi-tenant function without tenant-id header provided, user will see an internal server error, with this change user will see {"message":"The invoked function is enabled with tenancy configuration. Add a valid tenant ID in your request and try again.}
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.